home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d18 / turbotut.arc / AMORT3.PAS < prev    next >
Pascal/Delphi Source File  |  1989-06-30  |  2KB  |  73 lines

  1. PROGRAM amortization_table;
  2.  
  3. VAR month : 1..12;
  4.     starting_month : 1..12;
  5.     balance : REAL;
  6.     payment : REAL;
  7.     interest_rate : REAL;
  8.     annual_accum_interest : REAL;
  9.     year : INTEGER;
  10.  
  11. PROCEDURE initialize_data; (* ********************* initialize data *)
  12. BEGIN
  13.   balance := 2500.0;
  14.   starting_month := 5;
  15.   payment := 100.0;
  16.   interest_rate := 0.13/12.0;
  17.   annual_accum_interest := 0.0;  (* This is to accumulate Interest *)
  18.   year := 1985;
  19. END;
  20.  
  21. PROCEDURE print_annual_header; (* ************** print annual header *)
  22. BEGIN
  23.   WRITELN;
  24.   WRITELN('Month    payment  interest    princ   balance');
  25.   WRITELN;
  26. END;
  27.  
  28. PROCEDURE calculate_and_print; (* ************** calculate and print *)
  29. VAR interest_payment : REAL;
  30.     principal_payment : REAL;
  31. BEGIN
  32.   IF balance > 0.0 THEN
  33.   BEGIN
  34.     interest_payment := interest_rate * balance;
  35.     principal_payment := payment - interest_payment;
  36.     IF principal_payment > balance THEN
  37.     BEGIN  (* loan payed off this month *)
  38.       principal_payment := balance;
  39.       payment := principal_payment + interest_payment;
  40.       balance := 0.0;
  41.     END
  42.     ELSE
  43.     BEGIN  (* regular monthly payment *)
  44.       balance := balance - principal_payment;
  45.     END;
  46.     annual_accum_interest := annual_accum_interest + interest_payment;
  47.     WRITELN(month:5,payment:10:2,interest_payment:10:2,
  48.             principal_payment:10:2,balance:10:2);
  49.   END; (* of IF balance > 0.0 THEN *)
  50. END;
  51.  
  52. PROCEDURE print_annual_summary; (* ************ print annual summary *)
  53. BEGIN
  54.   WRITELN;
  55.   WRITELN('Total interest for ',year:5,' = ',
  56.            annual_accum_interest:10:2);
  57.   annual_accum_interest := 0.0;
  58.   year := year + 1;
  59.   WRITELN;
  60. END;
  61.  
  62. BEGIN   (* ********************************************* main program *)
  63.   initialize_data;
  64.   REPEAT
  65.     print_annual_header;
  66.     FOR month := starting_month TO 12 DO
  67.     BEGIN
  68.       calculate_and_print;
  69.     END;
  70.     print_annual_summary;
  71.     starting_month := 1;
  72.   UNTIL balance <= 0.0;
  73. END. (* of main program *)